package com.servlet;

import com.dao.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/uptest")
public class Modify extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
        try {
            updata(req,resp);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
//修改
    private void updata(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException, SQLException {
//        Integer sid = Integer.parseInt(req.getParameter("sid"));
        Integer sid = Integer.valueOf(req.getParameter("sid"));
        String studentno = req.getParameter("studentno");
        String sname = req.getParameter("sname");
        String gender = req.getParameter("gender");
        Integer age = Integer.parseInt(req.getParameter("age"));
        String address = req.getParameter("address");
        System.out.println(sid+" "+studentno+" "+sname+" "+gender+" "+age+" "+address);
        if (sid != null) {
            Student student = new Student();
            try {
                student.updataStudent(sid,studentno, sname, gender, age,address);
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
//            resp.sendRedirect("list.jsp");
            CheckServlet.check(req, resp);
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    }
}
